package cn.zjitc.service.impl;

import cn.zjitc.dao.AdminUserDao;
import cn.zjitc.entity.PageResult;
import cn.zjitc.entity.QueryPageBean;
import cn.zjitc.pojo.User;
import cn.zjitc.service.AdminUserService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = AdminUserService.class)
@Transactional
public class AdminUserServiceImpl implements AdminUserService {
    @Autowired
    private AdminUserDao adminUserDao;

    @Override
    public void add(User user) {
        adminUserDao.add(user);
    }

    @Override
    public void addborrow(User user){
        adminUserDao.addborrow(user);
    }

    @Override
    public void deleteById(Integer id) {
        adminUserDao.deleteById(id);
    }

    @Override
    public void deleteByIdBorrow(Integer id) {
        adminUserDao.deleteByIdborrow(id);
    }

    @Override
    public void edit(User user) {
        adminUserDao.edit(user);
    }

    @Override
    public void editborrow(User user) {
        adminUserDao.editborrow(user);
    }

    @Override
    public List<User> findAll() {
        return adminUserDao.findAll();
    }

    @Override
    public User findById(Integer id) {
        return adminUserDao.findById(id);
    }

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage,pageSize);
        Page<User> page = adminUserDao.findByCondition(queryString);
        long total = page.getTotal();
        List<User> rows = page.getResult();
        return new PageResult(total,rows);
    }

    @Override
    public User findByName(String username) {
        return adminUserDao.findByName(username);
    }

    @Override
    public void edituser(User user) {
        adminUserDao.edituser(user);
    }
}
